package com.cola.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Grup:com.cola.springmvc.controller
 * @Auther:cola
 * @Data:2021/4/21-2021-04-20:34
 * @version:1.0
 */
@Controller
@RequestMapping("/hello")
public class HelloWorld {
    //DispatcherServlet根据这个配置中的url地址决定调用那个方法,方法的返回值类型如果时字符串(string),
    // 说明返回的是一个视图的名字,DispatcherServlet会根据视图解析中的配置找到视图完整的路径,从而解析并显示视图
    @RequestMapping(value = "/world",method = RequestMethod.GET)
    public String helloworld(){
        System.out.println("hello world!");
        return "helloworld";
    }

    @RequestMapping(value = "/loginform")
    public String loginForm(){
        return "login";
    }
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public String login(@RequestParam(value = "realname") String username, String password){
        System.out.println("执行登录");
        System.out.println("username:"+username);
        System.out.println("password:"+password);
        return "redirect:world";
    }

    @RequestMapping("/testcookie")
    public String testCookieValue(@CookieValue("JSESSIONID") String sessionId){
        System.out.println(sessionId);
        return "success";
    }

    @RequestMapping("/testheader")
    public String testHeader(@RequestHeader("Accept-Language") String header){
        System.out.println(header);
        return "success";
    }
    //请求表达式
    @RequestMapping(value = "/testparam",params = {"username","age!=10"},headers = {"Accept-Language=zh-CN,zh-HK;q=0.9,zh-MO;q=0.8,zh-TW;q=0.7,zh;q=0.6"})
    public String testParam(String username,Integer age){
        System.out.println("username:"+username+" "+"age:"+age);
        return "success";
    }

    @RequestMapping("/testantpath/*/cola")
    public String testAntpath(){
        System.out.println("antpath");
        return "success";
    }
}
